import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'leader_rank_list.dart';
import 'dart:ui';

class leader_rank extends StatefulWidget {
  leader_rank({Key key}) : super(key: key);

  @override
  State<leader_rank> createState() => _leader_rankState();
}

class _leader_rankState extends State<leader_rank> {
  List<String> _menuStr = [
    'menu 1',
    'menu 2',
    'menu 3',
    'menu 4',
    'menu 5',
    'menu 6',
    'menu 7',
    'menu 8',
    'menu 9'
  ];

  List _menu_rank = [
    {'rank_name': '新作榜', 'rank_id': 1024},
    {'rank_name': '国漫榜', 'rank_id': 1025},
    {'rank_name': '日漫榜', 'rank_id': 1027},
    {'rank_name': '韩漫榜', 'rank_id': 1028},
    {'rank_name': '宝藏榜', 'rank_id': 1029},
    {'rank_name': '免费榜', 'rank_id': 1030},
    {'rank_name': '完结榜', 'rank_id': 1031},
  ];

  double hight_jump = 0;

  int _selectedIdx = 0;
  ScrollController _scrollController = new ScrollController();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _scrollController.addListener(() {});

    var s = window.physicalSize;
    print(s.height);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text(
          '排名',
          style: TextStyle(color: Colors.black),
        ),
        iconTheme: IconThemeData(
          color: Colors.black87, //修改颜色
        ),
        centerTitle: true,
      ),
      body: Row(
        children: <Widget>[
          Container(
            width: 100,
            child: ListView.builder(
              itemCount: _menu_rank.length,
              itemBuilder: (context, index) {
                String _rank_name = _menu_rank[index]['rank_name'];
                return GestureDetector(
                  onTap: () {
                    setState(() {
                      print(index);
                      _selectedIdx = index;

                      hight_jump = (index * 900).toDouble();
                      print(hight_jump);
                      _scrollController.animateTo(hight_jump,
                          duration: Duration(milliseconds: 500),
                          curve: Curves.ease);
                    });
                  },
                  child: Column(
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: 20, right: 10),
                        decoration: new BoxDecoration(
                          color: (_selectedIdx == index)
                              ? Color.fromRGBO(80, 200, 255, 1)
                              : Colors.white,
                          // 设置四周圆角，角度
                          borderRadius: BorderRadius.only(
                              topRight: Radius.circular(50.0),
                              bottomRight: Radius.circular(50.0)),
                        ),
                        height: 40,
                        // color: (_selectedIdx == index)
                        //     ? Colors.grey
                        //     : Colors.white,
                        child: Row(
                          children: <Widget>[
                            Expanded(
                              child: Center(
                                child: Text(_rank_name),
                              ),
                            )
                          ],
                        ),
                      ),
                    ],
                  ),
                );
              },
            ),
          ),
          Expanded(
            child: Container(
              color: Colors.white,
              child: ListView.builder(
                  // controller: ,
                  physics: NeverScrollableScrollPhysics(),
                  controller: _scrollController,
                  itemBuilder: (BuildContext context, int index) {
                    return Column(
                      children: _menu_rank.asMap().keys.map((e) {
                        return Container(
                          color: Colors.red,
                          constraints: BoxConstraints(maxHeight: 900),
                          child: Stack(
                            overflow: Overflow.clip,
                            children: [
                              Container(
                                height: 1000,
                                color: Colors.white,
                                child: leader_rank_list(
                                  rank_id: 1024,
                                ),
                              ),
                            ],
                          ),
                        );
                      }).toList(),
                    );
                  }),
              // child: RefreshIndicator(
              //   onRefresh: () async {
              //     //模拟网络请求
              //     print('上拉刷新');
              //     // print(cartoon_list0);
              //     await Future.delayed(Duration(milliseconds: 2000));
              //     //结束刷新
              //     return Future.value(true);
              //   },
              //   child: ListView.builder(
              //       // controller: _scrollController,
              //       itemBuilder: (BuildContext context, int index) {
              //     return Wrap();
              //   }),
              // ),
            ),
          )
        ],
      ),
    );
  }
}
